package aaaBlogger.img;

import java.util.Map;
import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.attilax.core;
import com.attilax.cmsPoster.BlogPubberAbs;
import com.attilax.cmsPoster.BlogPubberMainform;
import com.attilax.cmsPoster.Ipub;
import com.attilax.formH5.EncodeX;
import com.attilax.io.filex;
import com.attilax.io.pathx;
import com.attilax.secury.aes;
import com.attilax.text.strUtil;
import com.attilax.util.PropX;

public class SohuPubber  extends BlogPubberAbs implements Ipub,Ipub2{

	public static void main(String[] args) {
		Map puber = (Map) core.newx(("aaaBlogger.img.SohuPubber"));
		
	}
	@Override
	public void pub2(String p1tit, String context, FirefoxDriver driver) {
		
		String t = getAuthorTxt("sohu");
		context=context.replace("$attilax_blog_sign$", t);
				
				
				
		   driver.findElement(By.id("entrytitle")).clear();
		    driver.findElement(By.id("entrytitle")).sendKeys(p1tit);
		 //   driver.findElement(By.id("save")).click();
		    
		    
		  //--------------context 
			context = changeBlogLink(context);
			context = EncodeX.jsEncodeSingleQuoue(context);
			
			// p2_txt="test in html";
			String baseDir=pathx.classPathParent_jensyegeor()
					 + "/blogger";
			String js =filex.read(baseDir + "/db/" + BlogPubberMainform.blogName.get()
					 
					+ "/editor__form.js");
			String script = js.replace("@txt", context);

			// window.document.getElementById('editor').value='..xxx'
			driver.executeScript(script,
					driver.findElement(By.id("entrytitle")));
		
	}

	@Override
	public void login(FirefoxDriver driver, Object px2) {
		try {
			 driver.findElement(By.linkText("登录")).click();
		} catch (Exception e) {
			// TODO: handle exception
		}
		PropX px=(PropX) px2;
		String pwd_enced=px.getProperty("pwd").trim();
		 
		String pwd =aes.decrypt(pwd_enced, "iluvmole");
 
	    driver.findElement(By.name("account")).clear();
	    driver.findElement(By.name("account")).sendKeys("attilax");
	    driver.findElement(By.name("password")).clear();
	    driver.findElement(By.name("password")).sendKeys(pwd);
	    driver.findElement(By.id("login_toolbar")).click();
	//    driver.findElement(By.cssSelector("div.entriesAdd > a")).click();
		
	}
	
	
	  public boolean isInLoginForm(String title, String sou) {
		  
		  if(title.contains("搜狐账号"))
			  return true;
		if(sou.contains(("toolbar-login-btn")))
		return true;
		else
			return false;
//		PropX px=(PropX) propMap.get(blogName.get());
//		String loginFormStr =px.getProperty("loginFormStr");
//		
//		//if (title.equals(loginFormStr))
//		Set<String> set=strUtil.toSet(loginFormStr.trim());
//		if(set.contains(title))
//			return true;
//		return false;
	}


}
